<!--
 * @Author: [kangjie]
 * @Date: 2022-04-08 09:30:47
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-08 09:56:25
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>原生ajax</title>
  <script src="./js/qs-6.9.4.js"></script>
</head>
<body>
  <script>
    let qs = Qs;
    // 创建ajax实例对象
    let xhr = new XMLHttpRequest();
    //打开一个连接 请求方式 请求路径
    // get传递参数 查询字符串 使用qs进行转换
    let params={
      page:1,
      pageSize:10
    };
    let qsObj=qs.stringify(params);
    console.log(qsObj,'查询字符串');
    // xhr.open('get','http://121.199.0.35:8888/index/carousel/findAll'+'?'+qsObj);
    xhr.open('get','http://121.199.0.35:8888/index/carousel/findAll');
    // 设置请求头 --表单格式数据
    // xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    // xhr.setRequestHeader('Content-Type','application/json');
    // 发送请求 post携带参数携带请求体中
    // xhr.send(qs.stringify({id:1,name:'zhangsan'}));
    xhr.send();
    // xhr.send(JSON.stringify({id:1,name:'zhangsan'}));
    // 接收响应
    xhr.onreadystatechange = function(){
      if(xhr.readyState === 4 && xhr.status === 200){
        console.log(xhr.responseText);
      }
    }

  </script>
</body>
</html>